package com.gimi.cloud.bbp.dao.dao.stroe;

import com.gimi.cloud.bbp.dao.common.SqlProvider;
import com.gimi.cloud.bbp.dao.dao.sys.BaseDao;
import com.gimi.cloud.bbp.dao.myMapper.MyMapper;
import com.gimi.cloud.bbp.dto.store.StoreDTO;
import com.gimi.cloud.bbp.entity.store.StoreEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * Created by shazhiwei on 2017/12/20.
 */
@Mapper
public interface StoreDao extends MyMapper<StoreEntity>,BaseDao {
    /**
     * 根据商户id和商铺名称确认是否重复
     * @return
     */
    @Select("select * from ec_store where store_name=#{store_name} and merchant_id=#{merchant_id}")
    List<StoreEntity> storeExists(@Param(value = "store_name") String storeName,@Param(value = "merchant_id") String merchantId);

    @SelectProvider(type = SqlProvider.class,method = "sql")
    List<StoreDTO> findByCatIds(String sql);

    @Select("select store_id from ec_store where store_name LIKE CONCAT('%',#{storeName},'%') and merchant_id=#{merchantId}")
    List<String> findIdByName(@Param(value = "storeName") String storeName,@Param(value = "merchantId") String merchantId);

    @Select("SELECT store_id,store_name,merchant_id FROM ec_store WHERE merchant_id = #{merchantId} AND is_delete = 0;")
    List<StoreDTO> allStoreList(@Param(value = "merchantId") String merchantId);

    @SelectProvider(type = SqlProvider.class,method = "sql")
    Integer getCountBySql(String sql);

    @SelectProvider(type = SqlProvider.class,method = "sql")
    List<StoreDTO> selectBySql(String sql);
}
